package es.ibm.santillana.mdm.workflow.ValidarGenerales;
import java.util.Iterator;

import com.ibm.pim.catalog.Catalog;
import com.ibm.pim.catalog.item.Item;
import com.ibm.pim.collaboration.CollaborationCategory;
import com.ibm.pim.collaboration.CollaborationItem;
import com.ibm.pim.collaboration.CollaborationStep;
import com.ibm.pim.collaboration.CollaborationStepTransitionConfiguration;
import com.ibm.pim.collaboration.ItemCollaborationArea;
import com.ibm.pim.collection.PIMCollection;
import com.ibm.pim.extensionpoints.WorkflowStepFunction;
import com.ibm.pim.extensionpoints.WorkflowStepFunctionArguments;
import com.ibm.pim.utils.Logger;

import es.ibm.santillana.mdm.common.util.SantillanaLogger;
import es.ibm.santillana.mdm.integration.ItemChanges;


public class SuccesArgs implements WorkflowStepFunctionArguments,WorkflowStepFunction {

	

	@Override
	public Object getCustomParameter(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setCustomParameter(String arg0, Object arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public PIMCollection<CollaborationCategory> getCategories() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CollaborationStep getCollaborationStep() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PIMCollection<CollaborationItem> getItems() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CollaborationStepTransitionConfiguration getTransitionConfiguration() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void in(WorkflowStepFunctionArguments arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void out(WorkflowStepFunctionArguments arg0) {
		Logger log = SantillanaLogger.getLogger();
		System.out.println("ouuuuut");
		log.logInfo("OUT del Success:");
		PIMCollection <CollaborationItem> collabItem = arg0.getItems();

		Iterator <CollaborationItem> it = collabItem.iterator();
		
		while (it.hasNext()) {
			log.logInfo("DENTRO DE ITERATORRR:");
			CollaborationItem collabitem = it.next();
			ItemCollaborationArea colArea = (ItemCollaborationArea) collabitem.getCollaborationArea();
			Catalog ctg = colArea.getSourceCatalog();
			Item itm = ctg.getItemByPrimaryKey(collabitem.getPrimaryKey());
			ItemChanges itChanges = new ItemChanges(itm,collabitem);
			
			itChanges.writeAttribsAdd();
			
			itChanges.writeAttribsDel();
			
			itChanges.writeAttribsMod();
			
		}
		
	}

	@Override
	public void timeout(WorkflowStepFunctionArguments arg0) {
		// TODO Auto-generated method stub
		
	}

}
